<template>
  <el-dialog
    title="选择版本号"
    :visible.sync="visible"
    :before-close="close"
    append-to-body
    :close-on-click-modal="false"
    width="20%">
    <el-select v-model="selectVersion" value-key="checkVersionId" filterable placeholder="版本号" style="width: 100%">
      <el-option
        v-for="v in versions"
        :key="v.checkVersionId"
        :label="v.title"
        :value="v">
      </el-option>
    </el-select>
    <span slot="footer" class="dialog-footer">
      <el-button @click="close">取 消</el-button>
      <el-button class="pan-btn primary-btn" type="primary" @click="submit">确 定</el-button>
  	</span>
  </el-dialog>
</template>

<script>
  import { isBlank } from '@/common/js/utils'
  export default {
    data() {
    	return {
    		visible: false,
        versions: [],
        selectVersion: ''
    	}
    },
    props: ["childDataForm"],
    created() {
    	if (!isBlank(this.childDataForm)) {
        this.versions = this.childDataForm.map(v => {
          if (v.isCurrent == 0) {
            this.$set(v, 'title', v.recordNum + '-' + v.versionNum + '(当前版本)')
            if (typeof this.selectVersion != 'object') {
              this.selectVersion = v
            }
          }else{
            this.$set(v, 'title', v.recordNum + '-' + v.versionNum)
          }
          return v
        })
        this.visible = true
    	}
    },
    methods: {
      close(val) {
      	this.$emit('close')
        if (val === 'submit') {
          this.$emit('getSelectVersion', this.selectVersion)
        }
      	this.visible = false
      },
      submit() {
        this.close('submit')
      }
    }
  }
</script>

<style>
</style>
